package com.itheima.controller.backend.security;

import com.itheima.Service.OrdersettingService;
import com.itheima.common.entity.OrderSettingDTO;
import com.itheima.common.entity.OrdersettingVO;
import com.itheima.common.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class OrdersettingController {
    @Autowired
    private OrdersettingService ordersettingService;

    /**
     * 模板文件下载
     * @param response
     * @param fileName
     * @return
     */
    @GetMapping("/download")
    public String downloadFile(HttpServletResponse response, String fileName) throws Exception {
        log.info("模板文件下载:{}++:{}",fileName,response);
        ordersettingService.downloadFile(response,fileName);
        return "文件下载";
    }

    /**
     * 文件上传
     * @param excelFile
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public Result uploadFile(@RequestBody MultipartFile excelFile) throws Exception {
        log.info("文件上传:{}",excelFile);
        ordersettingService.uploadFile(excelFile);
        return new Result(true,"预约设置成功",null);
    }

    /**
     * 根据日期修改可预约人数
     * @return
     */
    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody OrderSettingDTO orderSettingDTO) throws Exception {
        log.info("根据日期修改可预约人数:{}",orderSettingDTO);
        ordersettingService.editNumberByOrderDate(orderSettingDTO);
        return new Result(true,"预约设置成功",null);
    }

    /**
     * 根据年月查询对应的预约设置信息
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String month) throws Exception {    // month: 2023-07
        log.info("根据年月查询对应的预约设置信息:{}",month);
        List<OrdersettingVO> ordersettingVOList= ordersettingService.getOrderSettingByMonth(month);
        return new Result(true,"获取预约设置数据成功",ordersettingVOList);
    }


}
